﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web.Mvc;

namespace VietThinks.Web.Mvc
{
    public abstract class HtmlElementBuilder
    {        
        protected HtmlHelper htmlHelper;        
        protected object htmlAttributes;

        public HtmlElementBuilder(HtmlHelper htmlHelper)
        {
            this.htmlHelper = htmlHelper;
        }

        public HtmlHelper HtmlHelper { get { return this.htmlHelper; } }                

        internal HtmlElementBuilder HtmlAttributesCore(object htmlAttributes)
        {
            this.htmlAttributes = htmlAttributes;

            return this;
        }

        public abstract string Build();

        public override string ToString()
        {
            return this.Build();
        }        
    }

    public static class HtmlElementBuilderExtensions
    {
        public static TBuilder HtmlAttributes<TBuilder>(this TBuilder builder, object htmlAttributes)
            where TBuilder : HtmlElementBuilder
        {
            return (TBuilder) builder.HtmlAttributesCore(htmlAttributes);
        }
    }    
}
